class Solution:
    def longestCommonPrefix(self, strs) -> str:
        prefix = ''
        if not strs or '' in strs: return prefix
        
        prefix = ''
        flag = True
        for i in range(0, len(strs[0])):
            flag = True
            begin = strs[0][i]
            for j in range(0, len(strs)):
                if len(strs[j]) <= i or begin != strs[j][i]:
                    flag = False
                    break
            if not flag: break
            prefix += begin
                
        return prefix

if __name__ == '__main__':
    s = Solution()
    L = []
    L = ['', 'a', 'b']
    # L = ['a', 'b', 'c']
    # L = ['a', 'abc', 'ab']
    # L = ['abcd', 'abcd', 'abcdefg']
    L = ['abcdefg', 'abcd', 'ab']
    result = s.longestCommonPrefix(L)
    print(result)